home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4078 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.8 KB  |  84 lines

  1. Path: csus.edu!news
  2. From: gustavo.sandoval@csus.edu (gustavo sandoval)
  3. Newsgroups: comp.lang.c++
  4. Subject: weird behavior
  5. Date: 27 Jan 1996 11:07:01 GMT
  6. Organization: Your Organization
  7. Message-ID: <4ed10l$jap@news.csus.edu>
  8. NNTP-Posting-Host: @u0106-p18.dialin.csus.edu
  9. Mime-Version: 1.0
  10. Content-Type: Text/Plain; charset=US-ASCII
  11. X-Newsreader: WinVN 0.99.7
  12.  
  13. I have the following linked list which I'm playing around with:
  14.  
  15. class CList
  16. {
  17. public:
  18.    CList(); 
  19.    ~CList();
  20.  
  21.    void Insert(int element);
  22.    void Print ();
  23.  
  24.    // Returns the number or items deleted
  25.    int  Delete(int target);
  26.    
  27. private:
  28.    CItem* head;
  29.  
  30. };// CList
  31.  
  32. // Implementation of the functions omitted 
  33.  
  34. // In main I have:
  35.  
  36. void main ()
  37. {
  38.    CList MyList;
  39.  
  40.    for (int x = 0; x < 10; x++ )
  41.       MyList.Insert (x*10);
  42.  
  43.    MyList.Print();
  44.  
  45.    int count = MyList.Delete (40);
  46.  
  47.    MyList.Insert (50);
  48.    MyList.Insert;           // <== this lines
  49.    MyList.Print;            // <== this lines
  50.  
  51.    count = MyList.Delete (50);
  52.  
  53. }
  54.  
  55.  
  56. note the lines with the arrows.  The code compiles in VC 4.0 without warnings 
  57. in level 4 or errors.  When I step through those two lines the debugger just 
  58. goes right by.  
  59.  
  60. Also I looked at the disassembly and I have the following:
  61.  
  62. 181:     MyList.Insert (50);
  63. 00401541   push      00000032
  64. 00401543   lea       ecx,dword ptr [MyList]
  65. 00401546   call      @ILT+10(?Insert@CList@@QAEXH@Z) (0040100a)
  66. 182:     MyList.Insert;
  67. 183:     MyList.Print;
  68. 184:
  69. 185:     count = MyList.Delete (50);
  70. 0040154b   push      00000032
  71. 0040154d   lea       ecx,dword ptr [MyList]
  72. 00401550   call      @ILT+65(?Delete@CList@@QAEHH@Z) (00401041)
  73. 00401555   mov       dword ptr [count],eax
  74.  
  75.  
  76. It just seems that the compiler is inserting no-ops.  Is this the right 
  77. behavior.  To me this seems like a bug that the compiler is not catching, but 
  78. then what do I know.
  79.  
  80. thanks in advance,
  81.  
  82. gustavo
  83.  
  84.